<?php

class wishlist extends cms_controller {

    //put your code here
    public function __construct() {
        parent::__construct();
        $this->load->model('wishlist_model', 'wlist');
    }

    public function index() {
        $data = $this->wlist->get(array('session_id' => $this->session->userdata('session_id')));
        $this->pass['data'] = $data;
        $this->themes->render('wishlist/index', $this->pass);
    }

    function add($id = false) {
        if ($id) {
            $this->load->model('products_model', 'product');
            $this->product->is_found(array('id' => $id), array(), 'row', $this->agent->referrer());
            $save['session_id'] = $this->session->userdata('session_id');
            if ($this->user_id)
                $save['user_id'] = $this->user_id;
            $save['product_id'] = $id;
            if ($this->wlist->save($save)) {
                $this->themes->set_message(array('type' => 'success', 'url' => $this->agent->referrer(), 'message' => 'message_save_success'));
            } else {
                get_save_error();
            }
        } else {
            show_404();
        }
    }

    function remove($id = false) {
        if ($id) {
            $this->load->model('products_model', 'product');
            if ($this->user_id) {
                $user = $this->user_id;
            } else {
                $user = '0';
            }
            $this->wlist->is_found(array('id' => $id, 'session_id' => $this->session->userdata('session_id')), array(), 'row', $this->agent->referrer());
            $save['session_id'] = $this->session->userdata('session_id');
            if ($this->user_id)
                $save['user_id'] = $this->user_id;
            $save['product_id'] = $id;
            if ($this->wlist->delete(array('id' => $id), FALSE)) {
                $this->themes->set_message(array('type' => 'success', 'url' => $this->agent->referrer(), 'message' => 'message_delete_success'));
            } else {
                get_save_error();
            }
        } else {
            show_404();
        }
    }

}

